package org.hzero.exam.api.controller.v1;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.*;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.exam.config.SwaggerTags;
import org.hzero.exam.domain.entity.HodrCompany;
import org.hzero.exam.domain.repository.HodrCompanyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 马旭阳
 * @date2019/8/5
 */
@Api(tags = SwaggerTags.COMPANY)
@RestController("companyController.v1")
@RequestMapping("/v1/{organizationId}/companys")
public class HodrCompanyController extends BaseController {
    @Autowired
    private HodrCompanyRepository companyRepository;
    @Permission(level = ResourceLevel.SITE,permissionPublic = true)
    @ApiOperation(value = "根据公司代码或公司全称分页查询公司信息")
    @GetMapping
    public ResponseEntity<Page<HodrCompany>> selectByCompanyNumberAndName(@PathVariable Long organizationId,
                                                                          @ApiParam(value = "公司代码")  String companyNumber,
                                                                          @ApiParam(value = "公司名称")  String companyName,
                                                                          PageRequest pageRequest){
        return Results.success(PageHelper.doPage(pageRequest,()->companyRepository.selectByCompanyIdAndName(companyNumber,companyName)));
    }
}
